package com.wd.live.view.activity;

import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.ItemTouchHelper;

import android.view.View;

import com.wd.live.R;
import com.wd.live.base.BaseActivity;
import com.wd.live.bean.FindConstellationBean;
import com.wd.live.databinding.ActivityMatchingBinding;
import com.wd.live.model.SpUtils;
import com.wd.live.model.utils.CardLayoutManager;
import com.wd.live.model.utils.ItemTouchHelperCallback;
import com.wd.live.view.adpater.XingzuoAdpater;
import com.wd.live.viewmodel.MainViewModel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MatchingActivity extends BaseActivity<MainViewModel, ActivityMatchingBinding> {

    List<FindConstellationBean.ResultBean> list = new ArrayList<>();
    @Override
    protected void initData() {
        String uid = SpUtils.getString("uid", "");
        String sid = SpUtils.getString("sid", "");
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId",uid);
        map.put("sessionId",sid);
        viewmodel.getConstellationlist(map,50,1).observe(MatchingActivity.this, new Observer<FindConstellationBean>() {
            @Override
            public void onChanged(FindConstellationBean findRecommendConstellationBean) {
                List<FindConstellationBean.ResultBean> result = findRecommendConstellationBean.getResult();
                list.addAll(result);
                databind.matchingRec.setLayoutManager(new CardLayoutManager());
                XingzuoAdpater adpater = new XingzuoAdpater(MatchingActivity.this, R.layout.constellation_adp, list);
                databind.matchingRec.setAdapter(adpater);
                ItemTouchHelperCallback itemTouchHelperCallback = new ItemTouchHelperCallback(list,adpater);
                ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback);
                itemTouchHelper.attachToRecyclerView(databind.matchingRec);
            }
        });
        databind.fanhui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


    }

    @Override
    protected int initLayout() {
        return R.layout.activity_matching;
    }

    @Override
    public void onChanged(Object o) {

    }
}